from es import getAddonPath, getclientvar, tell, usermsg
from langlib import Strings, getLangAbbreviation
from os.path import join

class stringsManager(object):
    def __init__(self, fileName):
        self.strings = Strings(join(getAddonPath('superdice'), 'data', fileName + '.ini'))

    def getPlayerLanguage(self, userid):    
        return getLangAbbreviation(getclientvar(userid, 'cl_language'))

    def getString(self, userid, string, tokens):
        return self.strings(string, tokens, self.getPlayerLanguage(userid)).replace('\\n', '\n')

    def tellString(self, userid, string, tokens):
        tell(userid, '#multi', '#green[#darkgreenSuperDice#green]#lightgreen ' + self.getString(userid, string, tokens))

    def rightTextString(self, userid, string, tokens):
        rightText(userid, self.getString(userid, string, tokens))

def rightText(userid, text):
    usermsg('create', 'panel', 'KeyHintText')
    usermsg('write', 'byte', 'panel', 1)
    usermsg('write', 'string', 'panel', text)
    usermsg('send', 'panel', userid)
    usermsg('delete', 'panel')


